var e = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e;
} : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
}, t = require("utils/md5.min.js");

App({
    onLaunch: function(t) {
        var n = this, a = this;
        a.savephone();
        var o = wx.getStorageSync("userInfo");
        if ("object" != (void 0 === o ? "undefined" : e(o))) wx.login({
            success: function(e) {
                e.code && (wx.setStorage({
                    key: "code",
                    data: e.code
                }), wx.getStorageSync("first_code") || wx.setStorage({
                    key: "first_code",
                    data: e.code
                }));
            }
        }); else {
            var i = "Array" == typeof o ? o.length > 0 : !!o;
            a.globalData.userInfo = i ? o : null;
        }
        var s = wx.getSystemInfoSync(), c = s.model, r = s.system, u = s.statusBarHeight, l = void 0;
        l = /iphone\s{0,}x/i.test(c) ? 88 : -1 !== r.indexOf("Android") ? 68 : 64, this.globalData.headerHeight = l, 
        this.globalData.statusBarHeight = u, this.globalData.system = r;
        var g = wx.getStorageSync("logs") || [];
        g.unshift(Date.now()), wx.setStorageSync("logs", g), wx.getSystemInfo({
            success: function(e) {
                n.globalData.navHeight = e.statusBarHeight, n.globalData.screenWidth = e.screenWidth;
                var t = 750 / e.screenWidth;
                n.globalData.screenHeight = e.screenHeight * t, n.globalData.version = e.version, 
                n.globalData.system = e.system, n.globalData.SDKVersion = e.SDKVersion;
            }
        });
        var f = this, d = f.getSecret();
        wx.request({
            url: f.globalData.haozuBase + "/api/miniapps/getcity/",
            data: {
                currtime: d.currtime,
                sign: d.sign
            },
            success: function(e) {
                200 === e.data.code && (f.globalData.domain = e.data.data.domain);
            },
            fail: function(e) {}
        }), wx.request({
            url: f.globalData.haozuBase + "/api/miniapps/getcitylist/",
            data: {
                currtime: d.currtime,
                sign: d.sign
            },
            success: function(e) {
                200 === e.data.code && (f.globalData.citys = e.data.data);
            },
            fail: function(e) {}
        });
    },
    globalData: {
        domain: "bj",
        citys: [],
        "tel-phone": "",
        userInfo: null,
        haozuBase: "https://www.haozu.com",
        uchaozuBase: "https://uc.haozu.com",
        tencentMapKey: "7A6BZ-DAZW6-ELWSU-ENCGS-NJAYS-X5FVC",
        liveBase: "https://mob.haozu.com",
        headerHeight: 0,
        statusBarHeight: 0,
        navHeight: 0,
        screenWidth: 0,
        screenHeight: 0,
        needBack: !1
    },
    getSecret: function() {
        var e = new Date().getTime() + "", n = [];
        return n.push("currtime=" + e.substr(0, 10)), n.push("Mini-1100-A01h-0000"), {
            currtime: e.substr(0, 10),
            sign: t(encodeURI(n.join("&")))
        };
    },
    getMobSecret: function(e, n, a, o) {
        var a = a || "GET", i = new Date().getTime() + "";
        i = i.substr(0, 10);
        var s = [], c = [];
        n.timestamp = i, n.valid_time = o || 60;
        for (var r in n) c.push(r);
        c.sort();
        for (var u in c) s.push(c[u] + "=" + encodeURIComponent(n[c[u]]));
        n.secret_id = "wxapp";
        var l = "mob.haozu.com" + e;
        return n.sign = t(a + l + s.join("&") + "KhBh-D9n8-O1Mi"), n;
    },
    extend: function(e) {
        function t(t, n, a, o) {
            return e.apply(this, arguments);
        }
        return t.toString = function() {
            return e.toString();
        }, t;
    }(function(t, n, a, o) {
        if ("object" === (void 0 === t ? "undefined" : e(t)) && "object" === (void 0 === n ? "undefined" : e(n))) for (var i in n) n.hasOwnProperty(i) && (i in t ? a || (o && "object" === e(t[i]) && "object" === e(n[i]) ? extend(t[i], n[i], a, o) : t[i] = n[i]) : t[i] = n[i]);
        return t;
    }),
    saveStorage: function(e, t) {
        var n = this, a = n.getSecret(), o = [ e ], i = wx.getStorageSync("browse") || [], s = wx.getStorageSync("building") || [], c = wx.getStorageSync("space") || [], r = wx.getStorageSync("website") || [];
        if (null !== n.globalData.userInfo) wx.request({
            url: "https://uc.haozu.com/api/miniapps/view/add",
            data: {
                uid: n.globalData.userInfo.user_id,
                currtime: a.currtime,
                sign: a.sign,
                data: o
            },
            success: function(e) {}
        }); else {
            var u = i.findIndex(function(t) {
                return t.v == e.v;
            });
            if (-1 !== u && i.splice(u, 1), i.unshift(e), wx.setStorageSync("browse", i), e.ca) {
                var l = r.findIndex(function(e) {
                    return e.id == t.id;
                });
                -1 !== l && r.splice(l, 1), r.unshift(t), wx.setStorageSync("website", r);
            } else if (1 == t.type) {
                var g = s.findIndex(function(e) {
                    return e.building_id == t.building_id;
                });
                -1 !== g && s.splice(g, 1), s.unshift(t), wx.setStorageSync("building", s);
            } else {
                var f = c.findIndex(function(e) {
                    return e.id == t.id;
                });
                -1 !== f && c.splice(f, 1), c.unshift(t), wx.setStorageSync("space", c);
            }
        }
    },
    savephone: function() {
        var e = this, t = e.getSecret();
        wx.request({
            url: e.globalData.haozuBase + "/api/miniapps/channelinfo/",
            data: {
                currtime: t.currtime,
                sign: t.sign
            },
            success: function(t) {
                200 == t.data.code && (e.globalData["tel-phone"] = t.data.data["tel-phone"]);
            },
            fail: function(e) {}
        });
    },
    orderlogin: function(e) {
        var t = this;
        if (!e.index) {
            var n = wx.getStorageSync("orderSaveId") || [];
            n.unshift(e), wx.setStorageSync("orderSaveId", n);
        }
        return new Promise(function(n, a) {
            var o = t.getSecret();
            wx.showLoading({
                mask: !0
            });
            var i = t.extend({
                domain: t.globalData.domain,
                name: "小程序预约",
                login: 1,
                from_page: 1,
                currtime: o.currtime,
                sign: o.sign
            }, e);
            wx.request({
                url: t.globalData.haozuBase + "/api/miniapps/intention/",
                data: i,
                success: function(e) {
                    if (wx.hideLoading(), 200 == e.data.code) {
                        if (n({
                            code: 200,
                            msg: "success"
                        }), t.globalData.userInfo) return;
                        wx.setStorage({
                            key: "userInfo",
                            data: e.data.data
                        }), t.globalData.userInfo = e.data.data, wx.getStorage({
                            key: "browse",
                            success: function(e) {
                                wx.request({
                                    url: "https://uc.haozu.com/api/miniapps/view/add",
                                    data: {
                                        uid: t.globalData.userInfo.user_id,
                                        currtime: o.currtime,
                                        sign: o.sign,
                                        data: e.data
                                    },
                                    success: function(e) {
                                        wx.removeStorage({
                                            key: "browse",
                                            success: function(e) {}
                                        }), wx.removeStorage({
                                            key: "building",
                                            success: function(e) {}
                                        }), wx.removeStorage({
                                            key: "space",
                                            success: function(e) {}
                                        });
                                    }
                                });
                            }
                        });
                    } else a(e.data), wx.showToast({
                        icon: "none",
                        title: e.data.msg,
                        mask: !0
                    });
                },
                fail: function(e) {
                    wx.showModal({
                        content: "登录失败，请重新登录",
                        success: function(e) {
                            e.confirm ? wx.navigateTo({
                                url: "/pages/login/index"
                            }) : e.cancel;
                        }
                    }), a(e);
                }
            });
        });
    },
    orderDisabled: function(e, t, n) {
        -1 !== (wx.getStorageSync("orderSaveId") || []).findIndex(function(e) {
            return e[n] == t;
        }) && e.setData({
            isYK: !0
        });
    },
    globalDataLoad: function(e, t, n) {
        var a = this;
        if (n || (n = t), a.globalData[t] && a.globalData[t].length > 0) {
            var o = {};
            o[n] = a.globalData[t], e.setData(o);
        } else {
            var i = setInterval(function() {
                if (a.globalData[t] && a.globalData[t].length > 0) {
                    var o = {};
                    o[n] = a.globalData[t], e.setData(o), clearInterval(i);
                }
            }, 300);
            setTimeout(function() {
                clearInterval(i);
            }, 1e4);
        }
    },
    compareVersion: function(e, t) {
        e = e.split("."), t = t.split(".");
        for (var n = Math.max(e.length, t.length); e.length < n; ) e.push("0");
        for (;t.length < n; ) t.push("0");
        for (var a = 0; a < n; a++) {
            var o = parseInt(e[a]), i = parseInt(t[a]);
            if (o > i) return 1;
            if (o < i) return -1;
        }
        return 0;
    },
    cameraPower: function() {
        return new Promise(function(e, t) {
            wx.getSetting({
                success: function(t) {
                    t.authSetting["scope.camera"] ? e(!0) : wx.authorize({
                        scope: "scope.camera",
                        success: function() {
                            console.log("授权成功"), e(!0);
                        },
                        fail: function() {
                            wx.showModal({
                                title: "提示",
                                content: "摄像头尚未进行授权，部分功能将无法使用",
                                showCancel: !1,
                                success: function(t) {
                                    t.confirm ? (console.log("用户点击确定"), wx.openSetting({
                                        success: function(t) {
                                            t.authSetting["scope.camera"] || wx.authorize({
                                                scope: "scope.camera",
                                                success: function() {
                                                    console.log("授权成功"), e(!0);
                                                },
                                                fail: function() {
                                                    console.log("用户点击取消"), e(!1);
                                                }
                                            });
                                        },
                                        fail: function() {
                                            console.log("授权设置录音失败"), e(!1);
                                        }
                                    })) : t.cancel && (console.log("用户点击取消"), e(!1));
                                }
                            });
                        }
                    });
                }
            });
        });
    },
    soundPower: function() {
        return new Promise(function(e, t) {
            wx.getSetting({
                success: function(t) {
                    t.authSetting["scope.record"] ? e(!0) : wx.authorize({
                        scope: "scope.record",
                        success: function() {
                            console.log("授权成功"), e(!0);
                        },
                        fail: function() {
                            wx.showModal({
                                title: "提示",
                                content: "录音功能尚未进行授权，部分功能将无法使用",
                                showCancel: !1,
                                success: function(t) {
                                    t.confirm ? wx.openSetting({
                                        success: function(t) {
                                            t.authSetting["scope.record"] || wx.authorize({
                                                scope: "scope.record",
                                                success: function() {
                                                    console.log("授权成功"), e(!0);
                                                },
                                                fail: function() {
                                                    console.log("用户点击取消"), e(!1);
                                                }
                                            });
                                        },
                                        fail: function() {
                                            console.log("授权设置录音失败"), e(!1);
                                        }
                                    }) : t.cancel && (console.log("用户点击取消"), e(!1));
                                }
                            });
                        }
                    });
                }
            });
        });
    }
});